* This do-file reproduces the results in Table 3 and Figures 3 and 4.

* Open dataset of responses from Qualtrics survey of MTurk respondents
use communal_mturk_data, clear

* Generate a variable indicating which "Communal Representation" condition a subject was in
gen communal=1 if Q30==1 | Q24==1 | Q27==1 | Q21==1 | Q14==1 | Q12==1 | Q15==1 | Q4==1 
replace communal=2 if Q31==1 | Q25==1 | Q28==1 | Q22==1 | Q5==1 | Q19==1 | Q13==1 | Q17==1 
replace communal=0 if  Q32==1 | Q26==1 | Q29==1 | Q23==1 | Q6==1 | Q20==1 | Q16==1 | Q18==1

label define communal 0 "Control" 1 "Follow public opinion" 2 "Follow what I think is best"
label values communal communal

* Generate a variable indicating which "personal representation" condition a subject was in
gen agreement=0 if ((Q30==1 | Q31==1 | Q32==1) & Q15_1==2 & Q15_2==1 & Q15_3==1) | ((Q24==1 | Q25==1 | Q26==1) & Q15_1==1 & Q15_2==2 & Q15_3==2) | ((Q27==1 | Q28==1 | Q29==1) & Q15_1==1 & Q15_2==2 & Q15_3==1) | ((Q21==1 | Q22==1 | Q23==1) & Q15_1==2 & Q15_2==1 & Q15_3==2) | ((Q14==1 | Q5==1 | Q6==1) & Q15_1==1 & Q15_2==1 & Q15_3==2) | ((Q12==1 | Q19==1 | Q20==1) & Q15_1==2 & Q15_2==2 & Q15_3==1) | ((Q13==1 | Q15==1 | Q16==1) & Q15_1==1 & Q15_2==1 & Q15_3==1) | ((Q4==1 | Q17==1 | Q18==1) & Q15_1==2 & Q15_2==2 & Q15_3==2) 
recode agreement .=1

label define yesno 0 "Full disagreement" 1 "Full agreement"
label values agreement yesno

* Drop respondents who did not correctly answer the attention check question
drop if Q35~=1

* Recode responses for whether the subject would support member of congress
recode Q7 5=1 4=2 2=4 1=5, gen(support_denny)
label define support 1 "Strongly oppose" 2 "Somewhat oppose" 3 "Neither support or oppose" 4 "Somewhat support" 5 "Strongly support"
label values support_denny support

* Recode "not sure" responses to missing for the questions about how well member 
* represents his district and how well he would represent the subject
recode Q8 4=., gen(represent_district)
recode Q9 4=., gen(self_represent)

label values represent_district A_18
label values self_represent A_18

* The following commands show effects of treatments on intevening variables
* Produces results shown in Figure 3
reg represent_district communal#agreement
margins, over( communal agreement)
marginsplot, xlabel(1 "Not well" 2 "Somewhat well" 3 "Very well     ", angle(0)) scheme(s1color) recast(scatter) plot2(m(T)) ytitle("Condition") title(" ") xtitle(" ")   horiz
graph export dist_represent.eps, replace

reg self_represent communal#agreement
margins, over( communal agreement)
marginsplot, xlabel(1 "Not well" 2 "Somewhat well" 3 "Very well     ", angle(0)) scheme(s1color) recast(scatter)  plot2(m(T)) ytitle("Condition") title(" ") xtitle(" ")   horiz
graph export self_represent.eps, replace


* Using IV Regression to look at effects of variables of interest on Support
* Identification happens through random assignment to treatment conditions
* Results presented in Table 3 and Figure 4
ivregress 2sls support_denny  (represent_district self_represent= communal#agreement) , first
margins, over(represent_district) at(self_represent=2)
marginsplot, ylabel(1 "Strongly Oppose" 2 3 4 5 "Strongly Support", angle(0))    scheme(s1color)  title(" ") xtitle("Represents the district") xlabel(, labs(small)) ytitle(" ") saving(dist, replace) aspect(1)
margins, over(self_represent) at(represent_district=2)
marginsplot, ylabel(1 "Strongly Oppose" 2 3 4 5 "Strongly Support", angle(0))   scheme(s1color)  title(" ") xtitle("Represents me personally") xlabel(, labs(small)) ytitle(" ")  saving(self, replace) aspect(1)
graph combine dist.gph self.gph, graphr(c(white)) iscale(.8)
graph export iveffects.eps, replace


* Instrumental variables regression results using ordered probit estimation
* Table A6 in supplementary information
* Need to install program to run. Type: ssc install cmp
cmp setup
cmp (support_denny = represent_district self_represent) (represent_district = communal#agreement) (self_represent = communal#agreement), ind($cmp_oprobit $cmp_oprobit $cmp_oprobit)
	

